#!/bin/sh

XRANDR=/usr/bin/xrandr

EXT_DISPLAY="VGA-0"	# or "DVI-0"
EXT_RESOLUTION="1280x1024" # SXGA
#EXT_RESOLUTION="1024x768"  # XGA

case "$1" in
    0|lcd_only)
	$XRANDR --output $EXT_DISPLAY --off
	$XRANDR --output LVDS         --auto
	;;
    1|lcd_ext)
	if ($XRANDR --query | grep -q "$EXT_DISPLAY connected"); then
	    $XRANDR --output LVDS         --mode $EXT_RESOLUTION
	    $XRANDR --output $EXT_DISPLAY --mode $EXT_RESOLUTION
	else
	    echo "External Display ($EXT_DISPLAY) is not connected."
	    exit 1
	fi
	;;
    2|ext_only)
	if ($XRANDR --query | grep -q "$EXT_DISPLAY connected"); then
	    $XRANDR --output $EXT_DISPLAY --mode $EXT_RESOLUTION
	    $XRANDR --output LVDS         --off
	else
	    echo "External Display ($EXT_DISPLAY) is not connected."
	    exit 1
	fi
	;;
    status)
	$XRANDR --query
	;;
    *)
	echo "Usage: $0 {0|1|2|status}"
	echo "     0 ... LCD only"
	echo "     1 ... LCD & External ($EXT_RESOLUTION)"
	echo "     2 ... External only  ($EXT_RESOLUTION)"
	echo "status ... Show status"
	exit 1
esac

exit 0
